<template>
  <a-card :bordered="false" style="min-height: 800px !important;">
    <a-steps class="steps" :current="currentTab">
      <a-step title="详填表说明" />
      <a-step title="基本信息" />
      <a-step title="专业信息" />
      <a-step title="具体证明材料" />
    </a-steps>
    <div class="content">
      <step1 v-if="currentTab === 0" @nextStep="nextStep" :status="status"/>
      <step2 v-if="currentTab === 1" @nextStep="nextStep" @prevStep="prevStep" :tes="professorInfo" :isNotChangeInfo="isNotChangeInfo" @setfiled="setfiled"/>
      <step3 v-if="currentTab === 2" @nextStep="nextStep" @prevStep="prevStep" :tes="professorInfo" :isNotChangeInfo="isNotChangeInfo" @setfiled1="setfiled1"/>
      <step4 v-if="currentTab === 3" @prevStep="prevStep" :status="status" :isShow="isShow" :geturl="geturl" :tes="professorInfo" :isNotChangeInfo="isNotChangeInfo" @setfiled2="setfiled2" @HandleOk="HandleOk" @ExportPDF2="ExportPDF2"/>
    </div>
  </a-card>
</template>

<script>
  import Step1 from './Step1'
  import Step2 from './Step2'
  import Step3 from './Step3'
  import Step4 from './Step4'
  import {getAction} from '@/api/manage'
  import {postAction} from '@/api/manage';
  import { httpAction } from '@/api/manage'
  export default {
    name: "StepForm",
    components: {
      Step1,
      Step2,
      Step3,
      Step4
    },
    data () {
      return {
        isShow:false,
        isIos:false,
        status:'',
        description: '将一个冗长或用户不熟悉的表单任务分成多个步骤，指导用户完成。',
        currentTab: 0,
        geturl:{
          url:'',
          show:false,
        },
        exportPdfUrl:"/org/exportProfessor/exportPDF",
        downloadPdfUrl:"/sys/common/static/",
        url:"/sendToDing2",
        isNotChangeInfo:'',
        professorInfo:{
          professorName:'',
          professorSex:'',
          professorBirthday:'',
          professorIdentity:'',
          professorEducationBackground:'',
          professorDegree:'',
          professorAddress:'',
          professorHomeAddress:'',
          professorHealth:'',
          professorOfficeTel:'',
          professorPhone:'',
          professorMajor:'',
          professorSchool:'',
          professorGraduateDate:'',
          professorDeclareCategory:'',
          professorWorkMajor:'',
          professorMajorDate:'',
          professorBeginWork:'',
          professorWorkUnit:'',
          professorPosition:'',
          professorTitle:'',
          professorProjectIntroduce:'',
          professorLeadMsg:'',
          professorApproveMsg:'',
          professorPhotoString:'',
          professorInfoPhotoString:'',
          professorIdString:'',
          professorCommitmentString:'',
          professorResumeString:'',
          professorDegreeImageString:'',
          professorQualificationString:'',
          professorOtherString:'',
        },
        // form
        form: null,
      }
    },
    created(){
      this.appSource();
      this.select();
    },
    methods: {
      appSource() {
        const u = navigator.userAgent, app = navigator.appVersion;
        const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isiOS) {
          this.isIos=true;
        }

      },
      HandleOk(){
          console.log("进入父组件提交");
          const that = this;
          let formType = this.professorInfo.professorDeclareCategory;
            // 访问后台，查找hasChild
            let url = "/sys/category/findById?ids="+formType;
            getAction(url).then((res) => {
              if (res.success) {
                if(res.result==0) {
                    console.log("进入提交状态");
                    let httpurl = this.url;
                    let method = '';
                    method = 'post';
                    console.log("表单提交数据",this.professorInfo);
                    httpAction(httpurl,this.professorInfo,method).then((res)=>{
                      if(res.success){
                        console.log("res:"+res);
                        that.isShow=true
                        that.$emit('ok');
                      }else{
                        that.$message.warning(res.message);
                      }
                    }).finally(() => {
                      that.close();
                    })
                }else{
                  this.$message.error("请选择具体的申报类型！")
                }
              }
            });
        },
      ExportPDF2(){
        let that=this
          postAction(this.exportPdfUrl,this.professorInfo).then((res)=>{
            let url = this.downloadPdfUrl+res.message
            console.log(url)
            if(this.isIos){
              that.geturl.url = window._CONFIG['domianURL']+url
              that.geturl.show =true
            }else
            {
              let a = document.createElement('a') //创建a标签
              a.href = window._CONFIG['domianURL']+url
              a.click()
            }

          })
      },
      setfiled(data){
        this.professorInfo.professorName=data.professorName;
        this.professorInfo.professorSex=data.professorSex;
        this.professorInfo.professorBirthday=data.professorBirthday;
        this.professorInfo.professorIdentity=data.professorIdentity;
        this.professorInfo.professorEducationBackground=data.professorEducationBackground;
        this.professorInfo.professorDegree=data.professorDegree;
        this.professorInfo.professorAddress=data.professorAddress;
        this.professorInfo.professorHomeAddress=data.professorHomeAddress;
        this.professorInfo.professorHealth=data.professorHealth;
        this.professorInfo.professorOfficeTel=data.professorOfficeTel;
        this.professorInfo.professorPhone=data.professorPhone;
      },
      setfiled1(data){
        this.professorInfo.professorMajor=data.professorMajor;
        this.professorInfo.professorSchool=data.professorSchool;
        this.professorInfo.professorGraduateDate=data.professorGraduateDate;
        this.professorInfo.professorDeclareCategory=data.professorDeclareCategory;
        this.professorInfo.professorWorkMajor=data.professorWorkMajor;
        this.professorInfo.professorMajorDate=data.professorMajorDate;
        this.professorInfo.professorBeginWork=data.professorBeginWork;
        this.professorInfo.professorWorkUnit=data.professorWorkUnit;
        this.professorInfo.professorPosition=data.professorPosition;
        this.professorInfo.professorTitle=data.professorTitle;
        this.professorInfo.professorProjectIntroduce=data.professorProjectIntroduce;
        this.professorInfo.professorLeadMsg=data.professorLeadMsg;
      },
      setfiled2(data){
        this.professorInfo.professorPhotoString=data.professorPhotoString;
        this.professorInfo.professorInfoPhotoString=data.professorInfoPhotoString;
        this.professorInfo.professorIdString=data.professorIdString;
        this.professorInfo.professorCommitmentString=data.professorCommitmentString;
        this.professorInfo.professorResumeString=data.professorResumeString;
        this.professorInfo.professorDegreeImageString=data.professorDegreeImageString;
        this.professorInfo.professorQualificationString=data.professorQualificationString;
        this.professorInfo.professorOtherString=data.professorOtherString;
        console.log("wangyueniao");
        console.log(data)
        },
      select(){
        getAction("/org/diyProfessorInfo/queryByDingUserId").then((res) => {
          console.log("ssssss")
          console.log(res.result)
          // 设置是否可以修改信息
            this.status=res.result.status;
            this.isNotChangeInfo = res.result.isChangeInfo == 0 ?true:false,
            this.professorInfo.professorName=res.result.professorName,
            this.professorInfo.professorSex=res.result.professorSex,
            this.professorInfo.professorSchool=res.result.professorSchool,
            this.professorInfo.professorBirthday=res.result.professorBirthday,
            this.professorInfo.professorPhotoString=res.result.professorPhotoString,
            this.professorInfo.professorMajor=res.result.professorMajor,
            this.professorInfo.professorGraduateDate=res.result.professorGraduateDate,
            this.professorInfo.professorEducationBackground=res.result.professorEducationBackground,
            this.professorInfo.professorDegree=res.result.professorDegree,
            this.professorInfo.professorWorkUnit=res.result.professorWorkUnit,
            this.professorInfo.professorAddress=res.result.professorAddress,
            this.professorInfo.professorDeclareCategory=res.result.professorDeclareCategory,
            this.professorInfo.professorPosition=res.result.professorPosition,
            this.professorInfo.professorBeginWork=res.result.professorBeginWork,
            this.professorInfo.professorTitle=res.result.professorTitle,
            this.professorInfo.professorWorkMajor=res.result.professorWorkMajor,
            this.professorInfo.professorMajorDate=res.result.professorMajorDate,
            this.professorInfo.professorIdentity=res.result.professorIdentity,
            this.professorInfo.professorHomeAddress=res.result.professorHomeAddress,
            this.professorInfo.professorHealth=res.result.professorHealth,
            this.professorInfo.professorOfficeTel=res.result.professorOfficeTel,
            this.professorInfo.professorPhone=res.result.professorPhone,
            this.professorInfo.professorProjectIntroduce=res.result.professorProjectIntroduce,
            this.professorInfo.professorLeadMsg=res.result.professorLeadMsg,
            this.professorInfo.professorApproveMsg=res.result.professorApproveMsg,
            this.professorInfo.professorInfoPhotoString=res.result.professorInfoPhotoString,
            this.professorInfo.professorIdString=res.result.professorIdString,
            this.professorInfo.professorCommitmentString=res.result.professorCommitmentString,
            this.professorInfo.professorResumeString=res.result.professorResumeString,
            this.professorInfo.professorDegreeImageString=res.result.professorDegreeImageString,
            this.professorInfo.professorQualificationString=res.result.professorQualificationString,
            this.professorInfo.professorOtherString=res.result.professorOtherString
        });
      },
      // handler
      nextStep () {
        if (this.currentTab < 3) {
          this.currentTab += 1
        }
      },
      prevStep () {
        if (this.currentTab > 0) {
          this.currentTab -= 1
        }
      },
    }
  }
</script>

<style lang="less" scoped>
  .steps {
    max-width: 750px;
    margin: 16px auto;
  }
</style>